a=input()
c=["zero", "one", "two", "three", "four", "five", "six" ,"seven", "eight", "nine"]
b=a.split()
e=""
wrong=False
for i in b:
    if i.isdigit() or not i in c or len(b)<3:
        print("Wrong input")
        wrong=True
        break
    else:
        e=str(e)
        u=c.index(i)
        e=e+str(u)
        e=int(e)

def is_prime(n):
    if not n%2:
        return n == 2
    d = 3
    while d*d <= n and n%d:
        d += 2
    return d*d > n
if not wrong:
    num = e
    tmp = abs(num-2)
    res = 2
    k = 3
    while True:
        if is_prime(k):
            t = abs(num-k)
            if t < tmp:
                tmp = t
                res = k
            else:
                print(res)
                break
        k += 2